var t = require("../../../mybehaviors/location/location"), a = getApp();

Page({
    behaviors: [ t ],
    data: {
        city: "",
        point: {
            lat: "",
            lng: ""
        },
        stores: [],
        inputs: "",
        isLoadMore: !0,
        page: 1,
        total_page: 0,
        showPage: !1,
        ok_subs_select: null,
        successLocation: !1,
        isOptionMenuMore: !1,
        activeType: "",
        subs_select: "",
        openTemplate: 0,
        screenMenu: [ {
            name: "商品",
            api: "plugin.store-cashier.frontend.store.goods.get-store-goods-list"
        }, {
            name: "门店",
            api: "plugin.store-cashier.frontend.store.goods.get-store-goods-by-title"
        } ],
        screenIndex: 1,
        screenShow: !1
    },
    onLoad: function(t) {
        var a = this;
        t.city && "1" !== t.city ? (t.city && this.setData({
            city: t.city
        }), t.point && this.setData({
            point: JSON.parse(t.point)
        }), this.gotoSearch()) : this._getLocation(function() {
            a.gotoSearch();
        });
    },
    onReady: function() {},
    onShow: function() {},
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {},
    onReachBottom: function() {
        this.data.isLoadMore ? (console.log("111111111111111"), this.getMoreData()) : console.log("没有更多数据");
    },
    onShareAppMessage: function() {
        var t = JSON.stringify(this.data.point);
        return {
            title: "",
            path: "/packageC/o2o/o2oSearch/o2oSearch?city=" + this.data.city + "&point=" + t
        };
    },
    setScreenShow: function() {
        this.setData({
            screenShow: !this.data.screenShow
        });
    },
    setScreenIndex: function(t) {
        var a = t.currentTarget.dataset.index;
        a != this.data.screenIndex && (this.setData({
            screenIndex: a,
            screenShow: !1
        }), this.gotoSearch());
    },
    gotoSearch: function() {
        var t = this, e = this;
        e.setData({
            page: 1,
            successLocation: !0
        });
        var s = a.getNetAddresss(this.data.screenMenu[this.data.screenIndex].api), i = a.qqMapTransBMap(parseFloat(e.data.point.lng), parseFloat(e.data.point.lat)), o = {};
        o = 0 == this.data.screenIndex ? {
            search: {
                keyword: this.data.inputs ? this.data.inputs : ""
            },
            lng: i.lng,
            lat: i.lat
        } : {
            kwd: this.data.inputs ? this.data.inputs : "",
            lng: i.lng,
            lat: i.lat,
            city_name: this.data.city,
            page: this.data.page
        }, a._postNetWork({
            url: s,
            data: o,
            success: function(a) {
                var s = a.data;
                1 == s.result ? (e.setData({
                    isLoadMore: !0,
                    total_page: s.data.last_page
                }), e.data.total_page || e.setData({
                    total_page: 0
                }), 0 == t.data.screenIndex ? t.setData({
                    listData: s.data.data
                }) : e.setData({
                    stores: s.data.data,
                    openTemplate: s.data.store_list_style || 0
                })) : e.setData({
                    stores: []
                }), e.setData({
                    showPage: !0
                });
            },
            fail: function(t) {
                console.log(t), e.setData({
                    showPage: !0
                });
            }
        });
    },
    getMoreData: function() {
        var t = this, e = this, s = this.data.isOptionMenuMore ? "plugin.store-cashier.frontend.store.goods.get-store-search" : this.data.screenMenu[this.data.screenIndex].api, i = a.getNetAddresss(s), o = a.qqMapTransBMap(parseFloat(e.data.point.lng), parseFloat(e.data.point.lat)), n = {};
        this.data.isOptionMenuMore ? (n = {
            lng: o.lng,
            lat: o.lat,
            city_name: o.city_name,
            is_type: o.this.data.activeType
        }, "classify" == this.data.activeType && (n.category_id = this.data.subs_select), 
        "distance" == this.data.activeType && (n.is_distance = this.data.subs_select)) : n = 0 == this.data.screenIndex ? {
            search: {
                keyword: this.data.inputs ? this.data.inputs : ""
            },
            lng: o.lng,
            lat: o.lat
        } : {
            kwd: this.data.inputs ? this.data.inputs : "",
            lng: o.lng,
            lat: o.lat,
            city_name: this.data.city,
            page: this.data.page
        }, this.setData({
            isLoadMore: !1
        }), this.data.page >= this.data.total_page ? console.log("111111111111111", this.data.page, this.data.total_page) : (this.setData({
            page: this.data.page + 1
        }), n.page = this.data.page, a._postNetWork({
            url: i,
            data: n,
            success: function(a) {
                var s = a.data;
                if (1 == s.result) {
                    e.setData({
                        isLoadMore: !0
                    });
                    var i = s.data.data;
                    0 == t.data.screenIndex ? e.setData({
                        listData: e.data.listData.concat(i)
                    }) : e.setData({
                        stores: e.data.stores.concat(i)
                    });
                } else e.setData({
                    page: e.data.page - 1,
                    isLoadMore: !1
                });
            },
            fail: function(t) {
                console.log(t);
            }
        }));
    },
    inpbtn: function(t) {
        var a = t.detail.value;
        this.setData({
            inputs: a
        });
    },
    changeOptiones: function(t) {
        this.data.isOptionMenuMore = !0, this.data.activeType = t.detail.activeType, this.data.subs_select = t.detail.subs_select, 
        console.log(t.detail);
        var e = this, s = a.qqMapTransBMap(parseFloat(e.data.point.lng), parseFloat(e.data.point.lat)), i = {
            lng: s.lng,
            lat: s.lat,
            city_name: this.data.city,
            is_type: t.detail.activeType
        };
        "classify" == t.detail.activeType && (i.category_id = t.detail.subs_select), "distance" == t.detail.activeType && (i.is_distance = t.detail.subs_select), 
        e.setData({
            stores: []
        });
        var o = a.getNetAddresss("plugin.store-cashier.frontend.store.goods.get-store-search");
        a._getNetWork({
            url: o,
            data: i,
            success: function(a) {
                var s = a.data;
                1 == s.result && (e.setData({
                    isLoadMore: !0,
                    page: 1,
                    total_page: s.data.last_page
                }), e.data.total_page || e.setData({
                    total_page: 0
                }), e.setData({
                    ok_subs_select: t.detail.subs_select,
                    stores: s.data.data
                }));
            },
            fail: function(t) {
                console.log(t);
            }
        });
    }
});